import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
import path from 'path'


const dependencies = require('./package.json').dependencies;
// https://vitejs.dev/config/
export default defineConfig({
  //base: '/user/',
   base:'/pc/',
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    })],
  resolve: {
    // Vite路径别名配置
    alias: {
      '@': path.resolve('./src')
    }
  },
  build: {
    minify: true, // 开启压缩
    rollupOptions: {
      treeshake: true, // 开启 Tree Shaking，消除未使用的代码，减小最终的包大小
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            // 指定需要拆分的第三方库或模块
           // console.info('id', id)
            const dependenciesKeys = Object.keys(dependencies);
            const match = dependenciesKeys.find((item) => {
              return id.includes(item);
            });
            console.info('match', match)
            const notSplit = ['vue', 'ant-design-vue'];
            if (match && !notSplit.includes(match)) {
              return match;
            }
          }
        },
      },
    }
  },
  server: {
    port: 3000,
    host: '0.0.0.0',
    proxy: {
      '/api': {
        target: 'http://192.168.2.213:8080',	//实际请求地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
    }
  }

})
